package com.foreknow.mapping;

import java.util.HashMap;
import java.util.Map;

/**
 * 工厂类
 */
public class MappingFactory {
    private static MappingFactory mappingFactory = null;
    private Map<String,EntityMapping> maps = new HashMap<>();
    public static final String ADMIN_MAPPING = "adminmapping";
    public static final String FOOD_MAPPING = "foodmapping";
    public static final String BUSINESS_MAPPING = "businessmapping";
    public static final String GUESTBOOK_MAPPING = "guestbookmapping";

    private MappingFactory(){

    }

    public static MappingFactory getInstance(){
        if (mappingFactory==null){
            mappingFactory = new MappingFactory();
            //向Map中保存xxxMapping对象
            mappingFactory.maps.put(ADMIN_MAPPING,new AdminMapping());
            mappingFactory.maps.put(FOOD_MAPPING,new FoodMapping());
            mappingFactory.maps.put(BUSINESS_MAPPING,new BusinessMapping());
            mappingFactory.maps.put(GUESTBOOK_MAPPING,new GuestBookMapping());
        }
        return mappingFactory;
    }

    //从Map集合中获取元素的方法
    public EntityMapping getMap(String key){
        return maps.get(key);
    }
}
